package com.fun_ordering.controller;

import com.fun_ordering.components.ApiResponse;
import com.fun_ordering.components.PageResult;
import com.fun_ordering.pojo.EmployeeTask;
import com.fun_ordering.service.EmployeeTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 员工任务表controller
 * @author XiaoPi
 *
 */
@RestController
@RequestMapping("/employeeTask")
public class EmployeeTaskController {

	@Autowired
	private EmployeeTaskService employeeTaskService;

	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findAll")
	public List<EmployeeTask> findAll(){
		return employeeTaskService.findAll();
	}


	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findPage")
	public PageResult  findPage(int page,int rows){
		return employeeTaskService.findPage(page, rows);
	}

	/**
	 * 增加
	 * @param employeeTask
	 * @return
	 */
	@RequestMapping("/add")
	public ApiResponse add(@RequestBody EmployeeTask employeeTask){
		try {
			employeeTaskService.add(employeeTask);
		return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
		return ApiResponse.failed(null);
		}
	}

	/**
	 * 修改
	 * @param employeeTask
	 * @return
	 */
	@RequestMapping("/update")
	public ApiResponse update(@RequestBody EmployeeTask employeeTask){
		try {
			employeeTaskService.update(employeeTask);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}

	/**
	 * 获取实体
	 * @param taskId
	 * @return
	 */
	@RequestMapping("/findOne")
	public EmployeeTask findOne(Integer taskId){
		return employeeTaskService.findOne(taskId);
	}

	/**
	 * 批量删除
	 * @param taskIds
	 * @return
	 */
	@RequestMapping("/delete")
	public ApiResponse delete(Integer [] taskIds){
		try {
			employeeTaskService.delete(taskIds);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}

		/**
	 * 查询+分页
	 * @param employeeTask
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/search")
	public PageResult search(@RequestBody EmployeeTask employeeTask, int page, int rows  ){
		return employeeTaskService.findPage(employeeTask, page, rows);
	}

}
